package com.qiyuexinxi.chat.controller;

import com.qiyuexinxi.chat.common.GenericResponse;
import com.qiyuexinxi.chat.constants.api.AttentionApi;
import com.qiyuexinxi.chat.constants.api.UserApi;
import com.qiyuexinxi.chat.dto.request.*;
import com.qiyuexinxi.chat.service.AttentionService;
import com.qiyuexinxi.chat.service.impl.AttentionServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author yangxingyu
 * @date 2020/3/6
 * @description
 */
@RestController
@Api(description = "关注相关接口")
public class AttentionController {

    @Autowired
    AttentionServiceImpl attentionService;

    @PostMapping(value = AttentionApi.ATTENTION_ADD, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "添加关注", notes = "添加关注")
    public GenericResponse addAttention(@Valid @RequestBody AttentionAddRequest attentionAddRequest){
        return new GenericResponse(attentionService.addAttention(attentionAddRequest));
    }

    @GetMapping(value = AttentionApi.ATTENTION_LIST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取关注列表", notes = "获取关注列表")
    public GenericResponse getAttentionList(@Valid AttentionRequest attentionRequest){
        return new GenericResponse(attentionService.getAttentionList(attentionRequest));
    }

    @GetMapping(value = AttentionApi.FANS_LIST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取粉丝列表", notes = "获取粉丝列表")
    public GenericResponse getFansList(@Valid AttentionRequest attentionRequest){
        return new GenericResponse(attentionService.getFansList(attentionRequest));
    }

    @PostMapping(value = AttentionApi.ATTENTION_DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "取消关注", notes = "取消关注")
    public GenericResponse deleteAttention(@Valid @RequestBody AttentionDeleteRequest attentionDeleteRequest){
        return new GenericResponse(attentionService.deleteAttention(attentionDeleteRequest));
    }

    @GetMapping(value = AttentionApi.IS_ATTENTION, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "判断用户userId是否关注用户attentionUserId", notes = "取消关注")
    public GenericResponse isAttention(@Valid IsAttentionRequest isAttentionRequest){
        return new GenericResponse(attentionService.isAttention(isAttentionRequest));
    }

}
